using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Security.Permissions;
using System.Windows.Forms;
namespace Win32SDK
{
    public sealed class User32
    {
        private User32()
        {
        }

        public const string Dll="user32.Dll";



        [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, uint uElapse, TimerProc lpTimerFunc);
        public delegate void TimerProc(IntPtr hWnd, uint uMsg, IntPtr nIDEvent, uint dwTime);

        // or alternatively
        [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, uint uElapse, IntPtr lpTimerFunc);


        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern int MessageBox(IntPtr hWnd, string text, string caption, int flags);






        [DllImport(User32.Dll, ExactSpelling = true, CharSet = CharSet.Auto)]
        public static extern uint TrackPopupMenuEx(
            IntPtr hmenu,
            TPM flags,
            int x,
            int y,
            IntPtr hwnd,
            IntPtr lptpm);


        [DllImport(User32.Dll)]
        public static extern bool GetCursorPos(out Point lpPoint);

        [DllImport(User32.Dll)]
        public static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint);

        [DllImport(User32.Dll)]
        public static extern bool ScreenToClient(IntPtr hWnd, ref Point lpPoint);

        [DllImport(User32.Dll)]
        public static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
        [DllImport(User32.Dll)]
        public static extern short GetKeyState(System.Windows.Forms.Keys vKey);
        // Methods
        [DllImport(User32.Dll, EntryPoint = "ChildWindowFromPointEx", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr _ChildWindowFromPointEx(HandleRef hwndParent, POINTSTRUCT pt, int uFlags);
        [DllImport(User32.Dll, EntryPoint = "WindowFromPoint", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr _WindowFromPoint(POINTSTRUCT pt);
        public static IntPtr BeginPaint(HandleRef hWnd, [In, Out, MarshalAs(UnmanagedType.LPStruct)] ref PAINTSTRUCT lpPaint)
        {
            return HandleCollector.Add(IntBeginPaint(hWnd, ref lpPaint), CommonHandles.HDC);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr CallNextHookEx(HandleRef hhook, int code, IntPtr wparam, IntPtr lparam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
        public static IntPtr ChildWindowFromPointEx(HandleRef hwndParent, int x, int y, int uFlags)
        {
            POINTSTRUCT pt = new POINTSTRUCT(x, y);
            return _ChildWindowFromPointEx(hwndParent, pt, uFlags);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int ClientToScreen(HandleRef hWnd, [In, Out] POINT pt);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool ClipCursor(COMRECT rcClip);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool ClipCursor(ref RECT rcClip);
       

        public static IntPtr CreateAcceleratorTable(HandleRef pentries, int cCount)
        {
            return HandleCollector.Add(IntCreateAcceleratorTable(pentries, cCount), CommonHandles.Accelerator);
        }


        public static IntPtr CreateMenu()
        {
            return HandleCollector.Add(IntCreateMenu(), CommonHandles.Menu);
        }

        public static IntPtr CreatePopupMenu()
        {
            return HandleCollector.Add(IntCreatePopupMenu(), CommonHandles.Menu);
        }

        public static IntPtr CreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, [MarshalAs(UnmanagedType.AsAny)] object pvParam)
        {
            return IntCreateWindowEx(dwExStyle, lpszClassName, lpszWindowName, style, x, y, width, height, hWndParent, hMenu, hInst, pvParam);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr DefFrameProc(IntPtr hWnd, IntPtr hWndClient, int msg, IntPtr wParam, IntPtr lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr DefMDIChildProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
  
        public static bool DestroyAcceleratorTable(HandleRef hAccel)
        {
            HandleCollector.Remove((IntPtr)hAccel, CommonHandles.Accelerator);
            return IntDestroyAcceleratorTable(hAccel);
        }

        public static bool DestroyIcon(HandleRef hIcon)
        {
            HandleCollector.Remove((IntPtr)hIcon, CommonHandles.Icon);
            return IntDestroyIcon(hIcon);
        }


        public static bool DestroyCursor(HandleRef hCurs)
        {
            HandleCollector.Remove((IntPtr)hCurs, CommonHandles.Cursor);
            return IntDestroyCursor(hCurs);
        }

        public static bool DestroyMenu(HandleRef hMenu)
        {
            HandleCollector.Remove((IntPtr)hMenu, CommonHandles.Menu);
            return IntDestroyMenu(hMenu);
        }

        public static bool DestroyWindow(HandleRef hWnd)
        {
            return IntDestroyWindow(hWnd);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr DispatchMessage([In] ref MSG msg);
        [DllImport(User32.Dll, CharSet = CharSet.Ansi, ExactSpelling = true)]
        public static extern IntPtr DispatchMessageA([In] ref MSG msg);
        [DllImport(User32.Dll, CharSet = CharSet.Unicode, ExactSpelling = true)]
        public static extern IntPtr DispatchMessageW([In] ref MSG msg);


        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool EnableMenuItem(HandleRef hMenu, int UIDEnabledItem, int uEnable);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
        public static extern bool EnableScrollBar(HandleRef hWnd, int nBar, int value);
        [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern bool EndDialog(HandleRef hWnd, IntPtr result);
        public static bool EndPaint(HandleRef hWnd, [In, MarshalAs(UnmanagedType.LPStruct)] ref PAINTSTRUCT lpPaint)
        {
            HandleCollector.Remove(lpPaint.hdc, CommonHandles.HDC);
            return IntEndPaint(hWnd, ref lpPaint);
        }

        [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildrenCallback lpEnumFunc, HandleRef lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool EnumThreadWindows(int dwThreadId, EnumThreadWindowsCallback lpfn, HandleRef lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr FindWindow(string className, string windowName);
       [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetActiveWindow();
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetAncestor(HandleRef hWnd, int flags);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern short GetAsyncKeyState(int vkey);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetCapture();
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool GetClassInfo(HandleRef hInst, string lpszClass, IntPtr h);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool GetClassInfo(HandleRef hInst, string lpszClass, [In, Out] WNDCLASS_I wc);
        [DllImport(User32.Dll)]
        public static extern int GetClassName(HandleRef hwnd, StringBuilder lpClassName, int nMaxCount);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool GetClientRect(HandleRef hWnd, [In, Out] ref RECT rect);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool GetClientRect(HandleRef hWnd, IntPtr rect);
       [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool GetCursorPos([In, Out] POINT pt);
        public static IntPtr GetDC(HandleRef hWnd)
        {
            return HandleCollector.Add(IntGetDC(hWnd), CommonHandles.HDC);
        }

        public static IntPtr GetDCEx(HandleRef hWnd, HandleRef hrgnClip, int flags)
        {
            return HandleCollector.Add(IntGetDCEx(hWnd, hrgnClip, flags), CommonHandles.HDC);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetDesktopWindow();
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetDlgItem(HandleRef hWnd, int nIDDlgItem);
        




        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetFocus();
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();
        [DllImport(Ole32.Dll, PreserveSig = false)]
        public static extern IntPtr GetHGlobalFromILockBytes(ILockBytes pLkbyt);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetKeyboardState(byte[] keystate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern short GetKeyState(int keyCode);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr GetMenu(HandleRef hWnd);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetMenuItemCount(HandleRef hMenu);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetMenuItemID(HandleRef hMenu, int nPos);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool GetMenuItemInfo(HandleRef hMenu, int uItem, bool fByPosition, [In, Out] MENUITEMINFO_T lpmii);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool GetMenuItemInfo(HandleRef hMenu, int uItem, bool fByPosition, [In, Out] MENUITEMINFO_T_RW lpmii);
        [DllImport(User32.Dll, CharSet = CharSet.Ansi, ExactSpelling = true)]
        public static extern bool GetMessageA([In, Out] ref MSG msg, HandleRef hWnd, int uMsgFilterMin, int uMsgFilterMax);
        [DllImport(User32.Dll, CharSet = CharSet.Unicode, ExactSpelling = true)]
        public static extern bool GetMessageW([In, Out] ref MSG msg, HandleRef hWnd, int uMsgFilterMin, int uMsgFilterMax);


       [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetParent(HandleRef hWnd);
       [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern IntPtr GetProcessWindowStation();
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool GetScrollInfo(HandleRef hWnd, int fnBar, SCROLLINFO si);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetSubMenu(HandleRef hwnd, int index);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetSystemMenu(HandleRef hWnd, bool bRevert);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetSystemMetrics(int nIndex);
        [DllImport(User32.Dll, SetLastError = true)]
        public static extern bool GetUserObjectInformation(HandleRef hObj, int nIndex, [MarshalAs(UnmanagedType.LPStruct)] USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetWindow(HandleRef hWnd, int uCmd);
        public static IntPtr GetWindowDC(HandleRef hWnd)
        {
            return HandleCollector.Add(IntGetWindowDC(hWnd), CommonHandles.HDC);
        }

        public static IntPtr GetWindowLong(HandleRef hWnd, int nIndex)
        {
            if (IntPtr.Size == 4)
            {
                return GetWindowLong32(hWnd, nIndex);
            }
            return GetWindowLongPtr64(hWnd, nIndex);
        }

        [DllImport(User32.Dll, EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr GetWindowLong32(HandleRef hWnd, int nIndex);
        [DllImport(User32.Dll, EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr GetWindowLongPtr64(HandleRef hWnd, int nIndex);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetWindowPlacement(HandleRef hWnd, ref WINDOWPLACEMENT placement);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool GetWindowRect(HandleRef hWnd, [In, Out] ref RECT rect);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);
       [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool InsertMenuItem(HandleRef hMenu, int uItem, bool fByPosition, MENUITEMINFO_T lpmii);
        [DllImport(User32.Dll, EntryPoint = "BeginPaint", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntBeginPaint(HandleRef hWnd, [In, Out] ref PAINTSTRUCT lpPaint);
        [DllImport(User32.Dll, EntryPoint = "CreateAcceleratorTable", CharSet = CharSet.Auto)]
        private static extern IntPtr IntCreateAcceleratorTable(HandleRef pentries, int cCount);
        [DllImport(User32.Dll, EntryPoint = "CreateMenu", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntCreateMenu();
        [DllImport(User32.Dll, EntryPoint = "CreatePopupMenu", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntCreatePopupMenu();
        [DllImport(User32.Dll, EntryPoint = "CreateWindowEx", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern IntPtr IntCreateWindowEx(int dwExStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width, int height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, [MarshalAs(UnmanagedType.AsAny)] object pvParam);
         [DllImport(User32.Dll, EntryPoint = "DestroyAcceleratorTable", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern bool IntDestroyAcceleratorTable(HandleRef hAccel);
        [DllImport(User32.Dll, EntryPoint = "DestroyCursor", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern bool IntDestroyCursor(HandleRef hCurs);

        [DllImport(User32.Dll, EntryPoint = "DestroyIcon", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern bool IntDestroyIcon(HandleRef hCurs);


        [DllImport(User32.Dll, EntryPoint = "DestroyMenu", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern bool IntDestroyMenu(HandleRef hMenu);
        [DllImport(User32.Dll, EntryPoint = "DestroyWindow", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool IntDestroyWindow(HandleRef hWnd);
        [DllImport(User32.Dll, EntryPoint = "EndPaint", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern bool IntEndPaint(HandleRef hWnd, ref PAINTSTRUCT lpPaint);
        [DllImport(User32.Dll, EntryPoint = "GetDC", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntGetDC(HandleRef hWnd);
        [DllImport(User32.Dll, EntryPoint = "GetDCEx", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntGetDCEx(HandleRef hWnd, HandleRef hrgnClip, int flags);
        [DllImport(User32.Dll, EntryPoint = "GetWindowDC", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern IntPtr IntGetWindowDC(HandleRef hWnd);
        [DllImport(User32.Dll, EntryPoint = "ReleaseDC", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern int IntReleaseDC(HandleRef hWnd, HandleRef hDC);
        [DllImport(User32.Dll, EntryPoint = "SetWindowRgn", CharSet = CharSet.Auto, ExactSpelling = true)]
        private static extern int IntSetWindowRgn(HandleRef hwnd, HandleRef hrgn, bool fRedraw);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool IsChild(HandleRef hWndParent, HandleRef hwnd);
        internal static bool IsComObject(object o)
        {
            return Marshal.IsComObject(o);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool IsDialogMessage(HandleRef hWndDlg, [In, Out] ref MSG msg);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool IsWindow(HandleRef hWnd);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool IsZoomed(HandleRef hWnd);
        [DllImport(User32.Dll, EntryPoint = "keybd_event", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern void Keybd_event(byte vk, byte scan, int flags, int extrainfo);
  

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, [In, Out] ref RECT rect, int cPoints);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int MapWindowPoints(HandleRef hWndFrom, HandleRef hWndTo, [In, Out] POINT pt, int cPoints);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int MsgWaitForMultipleObjects(int nCount, IntPtr pHandles, bool fWaitAll, int dwMilliseconds, int dwWakeMask);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern void NotifyWinEvent(int winEvent, HandleRef hwnd, int objType, int objID);
     

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool PeekMessage([In, Out] ref MSG msg, HandleRef hwnd, int msgMin, int msgMax, int remove);
        [DllImport(User32.Dll, CharSet = CharSet.Ansi)]
        public static extern bool PeekMessageA([In, Out] ref MSG msg, HandleRef hwnd, int msgMin, int msgMax, int remove);
        [DllImport(User32.Dll, CharSet = CharSet.Unicode)]
        public static extern bool PeekMessageW([In, Out] ref MSG msg, HandleRef hwnd, int msgMin, int msgMax, int remove);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, int lparam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, IntPtr lparam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool PostMessage(HandleRef hwnd, int msg, IntPtr wparam, IntPtr lparam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern void PostQuitMessage(int nExitCode);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern int PostThreadMessage(int id, int msg, IntPtr wparam, IntPtr lparam);
        [ReflectionPermission(SecurityAction.Assert, Unrestricted = true)]
        public static void PtrToStructure(IntPtr lparam, object data)
        {
            Marshal.PtrToStructure(lparam, data);
        }

        [ReflectionPermission(SecurityAction.Assert, Unrestricted = true)]
        public static object PtrToStructure(IntPtr lparam, Type cls)
        {
            return Marshal.PtrToStructure(lparam, cls);
        }

         [DllImport(User32.Dll, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern short RegisterClass(WNDCLASS_D wc);
        internal static int ReleaseComObject(object objToRelease)
        {
            return Marshal.ReleaseComObject(objToRelease);
        }

        public static int ReleaseDC(HandleRef hWnd, HandleRef hDC)
        {
            HandleCollector.Remove((IntPtr)hDC, CommonHandles.HDC);
            return IntReleaseDC(hWnd, hDC);
        }
        [DllImport(User32.Dll, ExactSpelling = true)]
        public static extern bool ReleaseCapture();


        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool RemoveMenu(HandleRef hMenu, int uPosition, int uFlags);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int ScreenToClient(HandleRef hWnd, [In, Out] POINT pt);
        [DllImport(User32.Dll, EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
        public static extern IntPtr SendCallbackMessage(HandleRef hWnd, int Msg, IntPtr wParam, IntPtr lParam);

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendDlgItemMessage(HandleRef hDlg, int nIDDlgItem, int Msg, IntPtr wParam, IntPtr lParam);


        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        public static void SendMessage(ref Message msg)
        {
            msg.Result = SendMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
        }
        

        
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, bool wParam, int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, int wParam, [In, Out] ref Rectangle lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int[] lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, [In, Out, MarshalAs(UnmanagedType.Bool)] ref bool wParam, IntPtr lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, ref short wParam, ref short lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, int wParam, IntPtr lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, string lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern int SendMessage(HandleRef hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.IUnknown)] out object editOle);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, StringBuilder lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] CHARFORMAT2A lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] CHARFORMATA lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] CHARFORMATW lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, CHARRANGE lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, EDITSTREAM64 lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int[] wParam, int[] lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, EDITSTREAM lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, ref int wParam, ref int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref HDLAYOUT hdlayout);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] ref LVFINDINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, HandleRef lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern int SendMessage(HandleRef hWnd, int msg, int wParam, ref LVHITTESTINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] ref LVITEM lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, int wParam, [In, Out] ref RECT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref TBBUTTON lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref TBBUTTONINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref TV_INSERTSTRUCT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, ref TV_ITEM lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, FINDTEXT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] LOGFONT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, LVBKIMAGE lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, LVCOLUMN lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, LVCOLUMN_T lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, LVGROUP lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, LVHITTESTINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SendMessage(HandleRef hWnd, int msg, int wParam, LVINSERTMARK lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] LVTILEVIEWINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, MCHITTESTINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, MSG lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out, MarshalAs(UnmanagedType.LPStruct)] PARAFORMAT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, POINT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, REPASTESPECIAL lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, [In, Out] SIZE lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, SYSTEMTIME lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, SYSTEMTIMEARRAY lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TCITEM_T lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TEXTRANGE lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TOOLINFO_T lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TOOLINFO_TOOLTIP lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TV_HITTESTINFO lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, IntPtr wParam, [In, Out] ref RECT lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, string lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int Msg, IntPtr wParam, ListViewCompareCallback pfnCompare);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, HandleRef wParam, int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, GETTEXTLENGTHEX wParam, int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, POINT wParam, int lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessage(HandleRef hWnd, int msg, POINT wParam, [In, Out] LVINSERTMARK lParam);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SendMessageTimeout(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam, int flags, int timeout, out IntPtr pdwResult);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetActiveWindow(HandleRef hWnd);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetActiveWindow(IntPtr hWnd);


        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetCapture(HandleRef hwnd);
        public static IntPtr SetClassLong(HandleRef hWnd, int nIndex, IntPtr dwNewLong)
        {
            if (IntPtr.Size == 4)
            {
                return SetClassLongPtr32(hWnd, nIndex, dwNewLong);
            }
            return SetClassLongPtr64(hWnd, nIndex, dwNewLong);
        }

        [DllImport(User32.Dll, EntryPoint = "SetClassLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetClassLongPtr32(HandleRef hwnd, int nIndex, IntPtr dwNewLong);
        [DllImport(User32.Dll, EntryPoint = "SetClassLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr SetClassLongPtr64(HandleRef hwnd, int nIndex, IntPtr dwNewLong);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetCursor(HandleRef hcursor);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool SetCursorPos(int x, int y);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetFocus(HandleRef hWnd);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool SetForegroundWindow(HandleRef hWnd);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int SetKeyboardState(byte[] keystate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
        public static extern bool SetLayeredWindowAttributes(HandleRef hwnd, int crKey, byte bAlpha, int dwFlags);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool SetMenu(HandleRef hWnd, HandleRef hMenu);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool SetMenuDefaultItem(HandleRef hwnd, int nIndex, bool pos);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SetMenuItemInfo(HandleRef hMenu, int uItem, bool fByPosition, MENUITEMINFO_T lpmii);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr SetParent(HandleRef hWnd, HandleRef hWndParent);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int SetScrollInfo(HandleRef hWnd, int fnBar, SCROLLINFO si, bool redraw);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
        public static extern int SetScrollPos(HandleRef hWnd, int nBar, int nPos, bool bRedraw);
         public static IntPtr SetWindowLong(HandleRef hWnd, int nIndex, HandleRef dwNewLong)
        {
            if (IntPtr.Size == 4)
            {
                return SetWindowLongPtr32(hWnd, nIndex, dwNewLong);
            }
            return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
        }

        public static IntPtr SetWindowLong(HandleRef hWnd, int nIndex, WndProc wndproc)
        {
            if (IntPtr.Size == 4)
            {
                return SetWindowLongPtr32(hWnd, nIndex, wndproc);
            }
            return SetWindowLongPtr64(hWnd, nIndex, wndproc);
        }

        [DllImport(User32.Dll, EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, HandleRef dwNewLong);
        [DllImport(User32.Dll, EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr32(HandleRef hWnd, int nIndex, WndProc wndproc);
        [DllImport(User32.Dll, EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, HandleRef dwNewLong);
        [DllImport(User32.Dll, EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLongPtr64(HandleRef hWnd, int nIndex, WndProc wndproc);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool SetWindowPlacement(HandleRef hWnd, [In] ref WINDOWPLACEMENT placement);
        public static int SetWindowRgn(HandleRef hwnd, HandleRef hrgn, bool fRedraw)
        {
            int num = IntSetWindowRgn(hwnd, hrgn, fRedraw);
            if (num != 0)
            {
                HandleCollector.Remove((IntPtr)hrgn, CommonHandles.GDI);
            }
            return num;
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowsHookEx(int hookid, HookProc pfnhook, HandleRef hinst, int threadid);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(HandleRef hWnd, string text);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(IntPtr hWnd, string text);



        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int ShowCursor(bool bShow);
        internal static int SizeOf(Type t)
        {
            return Marshal.SizeOf(t);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, bool[] flag, bool nUpdate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, ref int value, int ignore);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, ref RECT rc, int nUpdate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, [In, Out] LOGFONT font, int nUpdate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, [In, Out] NONCLIENTMETRICS metrics, int nUpdate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, ref bool value, int ignore);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, ref HIGHCONTRAST_I rc, int nUpdate);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern bool SystemParametersInfo(int nAction, int nParam, [In, Out] IntPtr[] rc, int nUpdate);
        internal static void ThrowExceptionForHR(int errorCode)
        {
            Marshal.ThrowExceptionForHR(errorCode);
        }

        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool TranslateMDISysAccel(IntPtr hWndClient, [In, Out] ref MSG msg);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool TranslateMessage([In, Out] ref MSG msg);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern bool UnhookWindowsHookEx(HandleRef hhook);

        [DllImport(User32.Dll, CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool UnregisterClass(string className, HandleRef hInstance);
        [DllImport(User32.Dll, CharSet = CharSet.Auto)]
        public static extern short VkKeyScan(char key);
        [DllImport(User32.Dll, CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern void WaitMessage();

        [DllImport(User32.Dll, SetLastError = true, ExactSpelling = true)]
        public static extern IntPtr WindowFromDC(HandleRef hDC);
        public static IntPtr WindowFromPoint(int x, int y)
        {
            POINTSTRUCT pt = new POINTSTRUCT(x, y);
            return _WindowFromPoint(pt);
        }


    }
}
